#include "TemperatureInfoPage.h"

#include "InnerTemperatureMonitor.h"
#include "MachineDependents.h"



TemperatureInfoPage::TemperatureInfoPage(const int pageNum) : BasePage(pageNum) {
    mpControllers = &ExtendDeviceManagerSingleton::instance().getExtendDevices(ExtendDeviceEnum::TEMPERATURE);
}


void TemperatureInfoPage::paint() {
    std::string content[4];

    resetStream();

    strStream << std::left << std::setw(13) << "temperatuInfo" << std::right << std::setw(3) << pageNum;
    content[0] = strStream.str();

    if (mpControllers->empty() ) {
        content[1] = ExtendDeviceEnum::NO_DEVICE.name;
    } else {
        ExtendDevicePtr extendDevicePtr = mpControllers->front().lock();
        if (nullptr == extendDevicePtr) {
            content[1] = ExtendDeviceEnum::NO_DEVICE.name;
        } else {
            InnerTemperatureMonitor* ptemperatureMonitor = static_cast<InnerTemperatureMonitor*> (extendDevicePtr->getDevice(ExtendDeviceEnum::TEMPERATURE));
            ptemperatureMonitor->updateInformation();

            content[1] = "threshold:";
            content[1].append(ptemperatureMonitor->mthreshold.second);

            content[2] = "temperatu:";
            content[2].append(ptemperatureMonitor->mtemperature.second);

        }

    }
    screen.show(&content[0], &content[1], &content[2], &content[3]);
}




